﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

namespace KetBanBonPhuong
{

    /// <summary>
    /// Summary description for CommentPost
    /// </summary>
    public class CommentPost
    {
        private int comment_id;

        public int Comment_id
        {
            get
            {
                return comment_id;
            }
            set
            {
                comment_id = value;
            }
        }

        private int post_id;

        public int Post_id
        {
            get
            {
                return post_id;
            }
            set
            {
                post_id = value;
            }
        }

        private int member_id;

        public int Member_id
        {
            get
            {
                return member_id;
            }
            set
            {
                member_id = value;
            }
        }

        private string text;

        public string Text
        {
            get
            {
                return text;
            }
            set
            {
                text = value;
            }
        }

        private DateTime created_date;

        public DateTime Created_date
        {
            get
            {
                return created_date;
            }
            set
            {
                created_date = value;
            }
        }

        public CommentPost()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public CommentPost(SqlDataReader sdr)
        {
            if (sdr != null && !sdr.IsClosed)
            {
                comment_id = sdr.GetInt32(0);
                if (!sdr.IsDBNull(1))
                    post_id = sdr.GetInt32(1);
                if (!sdr.IsDBNull(2))
                    member_id = sdr.GetInt32(2);
                if (!sdr.IsDBNull(3))
                    text = sdr.GetString(3);
                if (!sdr.IsDBNull(4))
                    created_date = sdr.GetDateTime(4);
            }
        }

        public static DataTable GetAll()
        {
            DBHelp dbh = new DBHelp();
            DataTable dt = new DataTable();
            string cmd = "CommentPost_GetAll";
            dt = dbh.ExecuteDataTable(cmd, CommandType.StoredProcedure);
            return dt;
        }

        public static DataTable GetAll(int PostID)
        {
            DBHelp dbh = new DBHelp();
            DataTable dt = new DataTable();
            dbh.AddParameter("@post_id", PostID);
            string cmd = "select * from tbl_comment_post where post_id = @post_id";
            dt = dbh.ExecuteDataTable(cmd, CommandType.Text);
            return dt;
        }


        //Ham lay ve ID nhan vao
        public static CommentPost GetInfo(int ID)
        {
            DBHelp dbh = new DBHelp();
            dbh.AddParameter("@omment_id", ID);
            CommentPost commentPost = new CommentPost();
            string cmd = "CommentPost_GetInfo";
            SqlDataReader sdr = dbh.ExecuteReader(cmd, CommandType.StoredProcedure);
            if (sdr.Read())
            {
                commentPost.Comment_id = sdr.GetInt32(0);
                if (!sdr.IsDBNull(1))
                    commentPost.Post_id = sdr.GetInt32(1);
                if (!sdr.IsDBNull(2))
                    commentPost.Member_id = sdr.GetInt32(2);
                if (!sdr.IsDBNull(3))
                    commentPost.Text = sdr.GetString(3);
                if (!sdr.IsDBNull(4))
                    commentPost.Created_date = sdr.GetDateTime(4);
            }
            return commentPost;
        }

        //Them commentPost
        public static void Insert(CommentPost commentPost)
        {
            DBHelp dbh = new DBHelp();
            dbh.AddParameter("@post_id", commentPost.Post_id);
            dbh.AddParameter("@member_id", commentPost.Member_id);
            dbh.AddParameter("@text", commentPost.Text);
            dbh.AddParameter("@created_date", commentPost.Created_date);
            string cmd = "CommentPost_Insert";
            dbh.ExecuteNonQuery(cmd, CommandType.StoredProcedure);
        }

        //Sua commentPost
        public static void Update(CommentPost commentPost)
        {
            DBHelp dbh = new DBHelp();
            dbh.AddParameter("@comment_id", commentPost.Comment_id);
            dbh.AddParameter("@post_id", commentPost.Post_id);
            dbh.AddParameter("@member_id", commentPost.Member_id);
            dbh.AddParameter("@text", commentPost.Text);
            dbh.AddParameter("@created_date", commentPost.Created_date);
            string cmd = "CommentPost_Update";
            dbh.ExecuteNonQuery(cmd, CommandType.StoredProcedure);
        }

        //Xoa commentPost
        public static void Delete(int ID)
        {
            DBHelp dbh = new DBHelp();
            dbh.AddParameter("@comment_id", ID);
            string cmd = "CommentPost_Delete";
            dbh.ExecuteNonQuery(cmd, CommandType.StoredProcedure);
        }

        // can thiet them sau
    }
}
